package org.makcro.sms.services.chat.web.client.widgets;

import org.makcro.sms.services.chat.web.shared.dto.HistoryItemDto;

import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public class HistoryCellRenderer implements GridCellRenderer<HistoryItemDto> {

	private Template	gridTemplate	= new Template( "<b>{fromNumber}:</b> {customerMessage}</br>" + "<b>Agent:</b> {agentMessage}" );

	@Override
	public Object render(HistoryItemDto model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<HistoryItemDto> store, Grid<HistoryItemDto> grid) {
		Params params = new Params();
		params.set( "fromNumber", model.getFromNumber() );
		params.set( "customerMessage", model.getQuestion() );
		params.set( "agentMessage", model.getAnswer() );

		String appliedTemplate = gridTemplate.applyTemplate( params );
		return appliedTemplate;
	}

}
